package com.lambda.hybrid.handler;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import com.lambda.hybrid.Callback;
import com.lambda.hybrid.R;

public class ShowHUDHandler extends AbstractHandler {
    private final FrameLayout mParentView;
    private ProgressBar mProgressBar;

    public ShowHUDHandler(FrameLayout parent) {
        mParentView = parent;
    }

    @Override
    public void onHandle(String data, final Callback callback) throws Exception {
        if (mProgressBar == null) {
            LayoutInflater.from(mParentView.getContext()).inflate(R.layout.layout_hud, mParentView, true);
            mProgressBar = mParentView.findViewById(R.id.hybrid_hud);
            mProgressBar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    v.setVisibility(View.GONE);
                    callback.invoke("{\"cancel\": true}");
                }
            });
        } else {
            mProgressBar.setVisibility(View.VISIBLE);
        }
    }
}
